package com.sun.dao;

import com.sun.pojo.Employee;
import com.sun.vo.EmployeeVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;

import java.util.List;

public interface EmployeeMapper {
    /**
     * 根据用户名查询登录用户
     * @param loginName
     * @return
     */
    Employee findEmployeeByLoginName(String loginName);

    /**
     * 根据部门ID查询该部门是否有员工
     * @param deptId
     * @return
     */
    int checkDeptHasEmployee(int deptId);

    /**
     * 根据部门ID查询该角色下是否有员工
     * @param roleId
     * @return
     */
    int checkRoleHasEmployee(int roleId);

    /**
     * 根据条件查询员工数据
     * @param employeeVo
     * @return
     */
    List<Employee> findEmployeeList(EmployeeVo employeeVo);

    /**
     * 添加员工
     * @param employee
     * @return
     */
    int addEmployee(Employee employee);

    /**
     * 修改员工信息
     * @param employee
     * @return
     */
    int updateEmployee(Employee employee);

    /**
     * 删除员工信息(真实删除)
     * @param id
     * @return
     */
    @Delete("delete from sys_employee where id = #{id}")
    int deleteEmployee(int id);

    /**
     * 删除员工之前删除员工角色表
     * @param id
     * @return
     */
    @Delete("delete from sys_role_employee where eid=#{id}")
    int deleteEmployeeAndRole(int id);

    @Insert("insert into sys_role_employee(eid,rid) values(#{id},#{checkedId})")
    void addEmployeeAndRole(@Param("id") int id, @Param("checkedId") String checkedId);

    /**
     * 根據员工ID删除所有角色-员工关系
     * @param id
     */
    @Delete("delete from sys_role_employee where eid=#{id}")
    int deleteAllRoleAndEmployee(int id);
}
